package com.ethan.lotmaster.mq;

import com.ethan.lotmaster.dao.DeviceInfo;
import com.ethan.lotmaster.dao.DeviceInfoDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class MqListener {
    @Autowired
    DeviceInfoDao deviceInfoDao;
    @RabbitListener(queues = "queue_lot_data")
    public void processMessage(String msg) {
        log.info("收到netty网关的消息---"+msg);
        DeviceInfo deviceInfo = new DeviceInfo();
        String[] strings = msg.split("#");
        deviceInfo.setSno(strings[0]);
        deviceInfo.setTemperature(strings[1]);
        deviceInfo.setVoltage(strings[2]);
        deviceInfo.setCount(strings[3]);
        deviceInfo.setCreateTime(new Date());
        deviceInfoDao.insert(deviceInfo);

    }

}
